. "$PSScriptRoot/common.ps1"
$commonPropsPath = Join-Path $rootFolder "common.props"
$depsChanged = $false
foreach ($project in $projects) {
    $projectFolder = Join-Path $rootFolder $project
    Set-Location $projectFolder
    dotnet list package --outdated | ForEach-Object {
        $line = $_.ToString().Trim()
        # 只处理以 > 开头的包行
        if ($line -match '^>\s*([A-Za-z0-9\._\-]+)\s+\S+\s+\S+\s+(\S+)$') {
            $pkg = $matches[1]
            $latest = $matches[2]
            if ($pkg -match '^[A-Za-z0-9\._\-]+$' -and $latest -match '^\d+(\.\d+)*(-[A-Za-z0-9]+)?$') {
                Write-Info "升级 $pkg 到 $latest"
                dotnet add package $pkg -v $latest
                $depsChanged = $true
            } else {
                Write-Host "跳过无效包或版本: $pkg $latest" -ForegroundColor Yellow
            }
        }
    }
}
if ($depsChanged) {
    $content = Get-Content $commonPropsPath -Raw
    if ($content -match '<PatchVersion>(\d+)</PatchVersion>') {
        $patch = [int]$matches[1] + 1
        $content = $content -replace '<PatchVersion>\d+</PatchVersion>', "<PatchVersion>$patch</PatchVersion>"
        Set-Content $commonPropsPath -Value $content
        Write-Info "依赖包有变化，PatchVersion 自动递增为 $patch"
    }
} else {
    Write-Info "依赖包均为最新，无需升级"
} 